{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "NDB_No               int64\n",
      "Shrt_Desc           object\n",
      "Water_(g)          float64\n",
      "Energ_Kcal           int64\n",
      "Protein_(g)        float64\n",
      "Lipid_Tot_(g)      float64\n",
      "Ash_(g)            float64\n",
      "Carbohydrt_(g)     float64\n",
      "Fiber_TD_(g)       float64\n",
      "Sugar_Tot_(g)      float64\n",
      "Calcium_(mg)       float64\n",
      "Iron_(mg)          float64\n",
      "Magnesium_(mg)     float64\n",
      "Phosphorus_(mg)    float64\n",
      "Potassium_(mg)     float64\n",
      "Sodium_(mg)        float64\n",
      "Zinc_(mg)          float64\n",
      "Copper_(mg)        float64\n",
      "Manganese_(mg)     float64\n",
      "Selenium_(mcg)     float64\n",
      "Vit_C_(mg)         float64\n",
      "Thiamin_(mg)       float64\n",
      "Riboflavin_(mg)    float64\n",
      "Niacin_(mg)        float64\n",
      "Vit_B6_(mg)        float64\n",
      "Vit_B12_(mcg)      float64\n",
      "Vit_A_IU           float64\n",
      "Vit_A_RAE          float64\n",
      "Vit_E_(mg)         float64\n",
      "Vit_D_mcg          float64\n",
      "Vit_D_IU           float64\n",
      "Vit_K_(mcg)        float64\n",
      "FA_Sat_(g)         float64\n",
      "FA_Mono_(g)        float64\n",
      "FA_Poly_(g)        float64\n",
      "Cholestrl_(mg)     float64\n",
      "dtype: object\n"
     ]
    }
   ],
   "source": [
    "import pandas\n",
    "food_info = pandas.read_csv(\"food_info.csv\")\n",
    "#print(type(food_info))\n",
    "print food_info.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(8618, 36)\n"
     ]
    }
   ],
   "source": [
    "#first_rows = food_info.head()\n",
    "#print first_rows\n",
    "#print(food_info.head(3))\n",
    "#print food_info.columns\n",
    "#print food_info.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#pandas uses zero-indexing\n",
    "#Series object representing the row at index 0.\n",
    "#print food_info.loc[0]\n",
    "\n",
    "# Series object representing the seventh row.\n",
    "#food_info.loc[6]\n",
    "\n",
    "# Will throw an error: \"KeyError: 'the label [8620] is not in the [index]'\"\n",
    "#food_info.loc[8620]\n",
    "#The object dtype is equivalent to a string in Python"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#object - For string values\n",
    "#int - For integer values\n",
    "#float - For float values\n",
    "#datetime - For time values\n",
    "#bool - For Boolean values\n",
    "#print(food_info.dtypes)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>NDB_No</th>\n",
       "      <th>Shrt_Desc</th>\n",
       "      <th>Water_(g)</th>\n",
       "      <th>Energ_Kcal</th>\n",
       "      <th>Protein_(g)</th>\n",
       "      <th>Lipid_Tot_(g)</th>\n",
       "      <th>Ash_(g)</th>\n",
       "      <th>Carbohydrt_(g)</th>\n",
       "      <th>Fiber_TD_(g)</th>\n",
       "      <th>Sugar_Tot_(g)</th>\n",
       "      <th>...</th>\n",
       "      <th>Vit_A_IU</th>\n",
       "      <th>Vit_A_RAE</th>\n",
       "      <th>Vit_E_(mg)</th>\n",
       "      <th>Vit_D_mcg</th>\n",
       "      <th>Vit_D_IU</th>\n",
       "      <th>Vit_K_(mcg)</th>\n",
       "      <th>FA_Sat_(g)</th>\n",
       "      <th>FA_Mono_(g)</th>\n",
       "      <th>FA_Poly_(g)</th>\n",
       "      <th>Cholestrl_(mg)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1003</td>\n",
       "      <td>BUTTER OIL ANHYDROUS</td>\n",
       "      <td>0.24</td>\n",
       "      <td>876</td>\n",
       "      <td>0.28</td>\n",
       "      <td>99.48</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>...</td>\n",
       "      <td>3069.0</td>\n",
       "      <td>840.0</td>\n",
       "      <td>2.80</td>\n",
       "      <td>1.8</td>\n",
       "      <td>73.0</td>\n",
       "      <td>8.6</td>\n",
       "      <td>61.924</td>\n",
       "      <td>28.732</td>\n",
       "      <td>3.694</td>\n",
       "      <td>256.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1006</td>\n",
       "      <td>CHEESE BRIE</td>\n",
       "      <td>48.42</td>\n",
       "      <td>334</td>\n",
       "      <td>20.75</td>\n",
       "      <td>27.68</td>\n",
       "      <td>2.70</td>\n",
       "      <td>0.45</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.45</td>\n",
       "      <td>...</td>\n",
       "      <td>592.0</td>\n",
       "      <td>174.0</td>\n",
       "      <td>0.24</td>\n",
       "      <td>0.5</td>\n",
       "      <td>20.0</td>\n",
       "      <td>2.3</td>\n",
       "      <td>17.410</td>\n",
       "      <td>8.013</td>\n",
       "      <td>0.826</td>\n",
       "      <td>100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>1011</td>\n",
       "      <td>CHEESE COLBY</td>\n",
       "      <td>38.20</td>\n",
       "      <td>394</td>\n",
       "      <td>23.76</td>\n",
       "      <td>32.11</td>\n",
       "      <td>3.36</td>\n",
       "      <td>2.57</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.52</td>\n",
       "      <td>...</td>\n",
       "      <td>994.0</td>\n",
       "      <td>264.0</td>\n",
       "      <td>0.28</td>\n",
       "      <td>0.6</td>\n",
       "      <td>24.0</td>\n",
       "      <td>2.7</td>\n",
       "      <td>20.218</td>\n",
       "      <td>9.280</td>\n",
       "      <td>0.953</td>\n",
       "      <td>95.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3 rows × 36 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    NDB_No             Shrt_Desc  Water_(g)  Energ_Kcal  Protein_(g)  \\\n",
       "2     1003  BUTTER OIL ANHYDROUS       0.24         876         0.28   \n",
       "5     1006           CHEESE BRIE      48.42         334        20.75   \n",
       "10    1011          CHEESE COLBY      38.20         394        23.76   \n",
       "\n",
       "    Lipid_Tot_(g)  Ash_(g)  Carbohydrt_(g)  Fiber_TD_(g)  Sugar_Tot_(g)  \\\n",
       "2           99.48     0.00            0.00           0.0           0.00   \n",
       "5           27.68     2.70            0.45           0.0           0.45   \n",
       "10          32.11     3.36            2.57           0.0           0.52   \n",
       "\n",
       "         ...        Vit_A_IU  Vit_A_RAE  Vit_E_(mg)  Vit_D_mcg  Vit_D_IU  \\\n",
       "2        ...          3069.0      840.0        2.80        1.8      73.0   \n",
       "5        ...           592.0      174.0        0.24        0.5      20.0   \n",
       "10       ...           994.0      264.0        0.28        0.6      24.0   \n",
       "\n",
       "    Vit_K_(mcg)  FA_Sat_(g)  FA_Mono_(g)  FA_Poly_(g)  Cholestrl_(mg)  \n",
       "2           8.6      61.924       28.732        3.694           256.0  \n",
       "5           2.3      17.410        8.013        0.826           100.0  \n",
       "10          2.7      20.218        9.280        0.953            95.0  \n",
       "\n",
       "[3 rows x 36 columns]"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Returns a DataFrame containing the rows at indexes 3, 4, 5, and 6.\n",
    "#food_info.loc[3:6]\n",
    "\n",
    "# Returns a DataFrame containing the rows at indexes 2, 5, and 10. Either of the following approaches will work.\n",
    "# Method 1\n",
    "#two_five_ten = [2,5,10] \n",
    "#food_info.loc[two_five_ten]\n",
    "\n",
    "# Method 2\n",
    "#food_info.loc[[2,5,10]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Series object representing the \"NDB_No\" column.\n",
    "#ndb_col = food_info[\"NDB_No\"]\n",
    "#print ndb_col\n",
    "# Alternatively, you can access a column by passing in a string variable.\n",
    "#col_name = \"NDB_No\"\n",
    "#ndb_col = food_info[col_name]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#columns = [\"Zinc_(mg)\", \"Copper_(mg)\"]\n",
    "#zinc_copper = food_info[columns]\n",
    "#print zinc_copper\n",
    "#print zinc_copper\n",
    "# Skipping the assignment.\n",
    "#zinc_copper = food_info[[\"Zinc_(mg)\", \"Copper_(mg)\"]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   Water_(g)  Protein_(g)  Lipid_Tot_(g)  Ash_(g)  Carbohydrt_(g)  \\\n",
      "0      15.87         0.85          81.11     2.11            0.06   \n",
      "1      15.87         0.85          81.11     2.11            0.06   \n",
      "2       0.24         0.28          99.48     0.00            0.00   \n",
      "\n",
      "   Fiber_TD_(g)  Sugar_Tot_(g)  FA_Sat_(g)  FA_Mono_(g)  FA_Poly_(g)  \n",
      "0           0.0           0.06      51.368       21.021        3.043  \n",
      "1           0.0           0.06      50.489       23.426        3.012  \n",
      "2           0.0           0.00      61.924       28.732        3.694  \n"
     ]
    }
   ],
   "source": [
    "#print(food_info.columns)\n",
    "#print(food_info.head(2))\n",
    "col_names = food_info.columns.tolist()\n",
    "#print col_names\n",
    "gram_columns = []\n",
    "\n",
    "for c in col_names:\n",
    "    if c.endswith(\"(g)\"):\n",
    "        gram_columns.append(c)\n",
    "gram_df = food_info[gram_columns]\n",
    "print(gram_df.head(3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
